#pragma once
#include "../stdafx.h"
#include "Coordinate.h"
	class Coordinate;
	class AABB;

	class Plane
	{
	public:
		Plane(D3DXVECTOR3,float);
		~Plane();
		D3DXVECTOR3 m_n;
		float m_d;
	};

	class Ray
	{
	public:
		Ray();
		Ray(D3DXVECTOR3,D3DXVECTOR3);
		~Ray();
		inline void DeTransform(const D3DXMATRIX& m)
		{
			D3DXMATRIX mInv;
			D3DXMATRIX tmp=m;
			m_pos.x-=tmp.m[0][3];
			m_pos.y-=tmp.m[1][3];
			m_pos.z-=tmp.m[2][3];
			tmp.m[0][3]=0.0f;
			tmp.m[1][3]=0.0f;
			tmp.m[2][3]=0.0f;
			D3DXMatrixInverse(&mInv,NULL,&tmp);
			D3DXVec3TransformCoord(&m_pos,&m_pos,&mInv);
			D3DXVec3TransformCoord(&m_direction,&m_direction,&mInv);

		}
		bool Intersects(const AABB&,float*);
		bool Intersects(const Plane&,D3DXVECTOR3*);
	private:
		D3DXVECTOR3 m_pos;
		D3DXVECTOR3 m_direction;
	};

	class AABB
	{
	public:
		//AABB(void);
		AABB(D3DXVECTOR3,D3DXVECTOR3,float);
		AABB(D3DXVECTOR2);

		AABB* TransToView(D3DXMATRIX&);

		void CreateCoord();
		~AABB(void);
		bool CalcVertices();
		D3DXVECTOR3 m_max;
		D3DXVECTOR3 m_min;
		D3DXVECTOR3 m_center;
		D3DXVECTOR3 m_pos[8];
		float m_hwidth;
		float m_hheight;
	};